/**
 * Created whit IntelliJ IDEA.
 * Description：
 * User：ZHONGCHEN
 * Date:2022-04-22
 * Time:23:07
 */
/**
 * 396. 旋转函数-找规律*/
public class TestDemo {
    public int maxRotateFunction(int[] nums) {
        long sum = 0;
        int length = nums.length;
        long pre = 0;
        long cur = 0;
        long max = 0;
        for (int i = 0; i < length; i++) {
            pre += i * nums[i];
            sum += nums[i];
        }

        max = pre;
        for (int i = 1; i < length; i++) {
            cur = pre - sum + length * nums[i - 1];
            max = Math.max(cur, max);
            pre = cur;
        }
        return (int)max;
    }
}
